use std::env;
use std::path::PathBuf;
use std::process;

pub mod cmd;
pub mod context;
pub mod errors;
pub mod util;

fn main() {
    let args = argh::from_env::<cmd::Args>();

    let context = context::Context {
        datadir: args.datadir.unwrap_or_else(|| PathBuf::from(".")),
    };

    eprintln!("[init] datadir: {:?}", context.datadir);

    if let Err(e) = cmd::exec_subc(args.subc, context) {
        eprintln!("[error] {}", e);
        process::exit(e.exitcode() as i32);
    }
}
